From e5a01976cb665b824b2ad6426a2c52a5bd0964e6 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Sat, 27 Jul 2024 08:27:54 +0700
Subject: <iman> add feature category lob

---
 src/pages/shop/lob/[slug].jsx | 73 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)
 create mode 100644 src/pages/shop/lob/[slug].jsx

(limited to 'src/pages/shop/lob/[slug].jsx')

diff --git a/src/pages/shop/lob/[slug].jsx b/src/pages/shop/lob/[slug].jsx
new file mode 100644
index 00000000..be8db639
--- /dev/null
+++ b/src/pages/shop/lob/[slug].jsx
@@ -0,0 +1,73 @@
+import _ from 'lodash';
+import dynamic from 'next/dynamic';
+import { useRouter } from 'next/router';
+import Seo from '@/core/components/Seo';
+import { getIdFromSlug, getNameFromSlug } from '@/core/utils/slug';
+import Breadcrumb from '@/lib/category/components/Breadcrumb';
+import { useEffect, useState } from 'react';
+import odooApi from '@/core/api/odooApi';
+
+const BasicLayout = dynamic(() => import('@/core/components/layouts/BasicLayout'));
+const ProductSearch = dynamic(() => import('@/lib/product/components/ProductSearch'));
+const CategorySection = dynamic(() => import('@/lib/product/components/CategorySection'));
+
+export default function CategoryDetail() {
+  const router = useRouter();
+  const { slug = '', page = 1 } = router.query;
+  const [dataLob, setDataLob] = useState([]);
+  const [finalQuery, setFinalQuery] = useState({});
+  
+  const categoryName = getNameFromSlug(slug);
+  const lobId = getIdFromSlug(slug);
+
+  useEffect(() => {
+    const fetchCategoryData = async () => {
+      try {
+        const lobData = await odooApi('GET', `/api/v1/lob_homepage?lob_id=${lobId}`);
+        setDataLob(lobData);
+      } catch (error) {
+        console.error("Error fetching category data:", error);
+      }
+    };
+
+    fetchCategoryData();
+  }, [lobId]);
+
+  console.log("dataLob",dataLob)
+  
+  useEffect(() => {
+      const collectIds = (categories) => {
+          return categories?.categoryIds?.map(data => data.id) || [];
+        };
+        
+        const ids = collectIds(dataLob[0]);
+        const newQuery = {
+            fq: `category_id_ids:(${ids.join(' OR ')})`,
+            page: 1,
+            brand: router.query.brand || '',
+        };
+        setFinalQuery(newQuery);
+        console.log("finalQuery",finalQuery)
+  }, [dataLob, router.query.brand]);
+
+  return (
+    <BasicLayout>
+      <Seo
+        title={`Beli ${categoryName} di Indoteknik`}
+        description={`Jual ${categoryName} Kirim Jakarta Surabaya Semarang Makassar Manado Denpasar Balikpapan Medan Palembang Lampung Bali Bandung Makassar Manado.`}
+        additionalMetaTags={[
+          {
+            property: 'keywords',
+            content: `Jual ${categoryName}, harga ${categoryName}, ${categoryName} murah, toko ${categoryName}, ${categoryName} jakarta, ${categoryName} surabaya`,
+          },
+        ]}
+      />
+
+      <Breadcrumb categoryId={getIdFromSlug(slug)} />
+
+      {!_.isEmpty(router.query) && (
+        <ProductSearch query={finalQuery} categories={getIdFromSlug(slug)} prefixUrl={`/shop/lob/${slug}`} />
+      )}
+    </BasicLayout>
+  );
+}
-- 
cgit v1.2.3


From f1910544cf6df50bcb175b66b604f5903f6ae3fa Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Sat, 27 Jul 2024 13:34:00 +0700
Subject: <iman> update category management for lob

---
 src/pages/shop/lob/[slug].jsx | 71 ++++++++++++++++++++++++++++++++-----------
 1 file changed, 54 insertions(+), 17 deletions(-)

(limited to 'src/pages/shop/lob/[slug].jsx')

diff --git a/src/pages/shop/lob/[slug].jsx b/src/pages/shop/lob/[slug].jsx
index be8db639..d02ec8ac 100644
--- a/src/pages/shop/lob/[slug].jsx
+++ b/src/pages/shop/lob/[slug].jsx
@@ -3,9 +3,10 @@ import dynamic from 'next/dynamic';
 import { useRouter } from 'next/router';
 import Seo from '@/core/components/Seo';
 import { getIdFromSlug, getNameFromSlug } from '@/core/utils/slug';
-import Breadcrumb from '@/lib/category/components/Breadcrumb';
+import Breadcrumb from '../../../lib/lob/components/Breadcrumb';
 import { useEffect, useState } from 'react';
 import odooApi from '@/core/api/odooApi';
+import { div } from 'lodash-contrib';
 
 const BasicLayout = dynamic(() => import('@/core/components/layouts/BasicLayout'));
 const ProductSearch = dynamic(() => import('@/lib/product/components/ProductSearch'));
@@ -16,9 +17,20 @@ export default function CategoryDetail() {
   const { slug = '', page = 1 } = router.query;
   const [dataLob, setDataLob] = useState([]);
   const [finalQuery, setFinalQuery] = useState({});
+  const [dataCategoriesProduct, setDataCategoriesProduct] = useState([])
+  const [data, setData] = useState([])
+  const dataIdCategories = []
   
   const categoryName = getNameFromSlug(slug);
   const lobId = getIdFromSlug(slug);
+  const q = router?.query.q || null;
+  const query = {
+    fq: `id:${lobId}`,
+    page,
+  };
+  if (q) {
+    query.q = q;
+  }
 
   useEffect(() => {
     const fetchCategoryData = async () => {
@@ -33,22 +45,40 @@ export default function CategoryDetail() {
     fetchCategoryData();
   }, [lobId]);
 
-  console.log("dataLob",dataLob)
-  
+  const collectIdsCategory = (category) => {
+    const ids = [];
+    function recurse(cat) {
+      if (cat && cat.id) {
+        ids.push(cat.id);
+      }
+      if (Array.isArray(cat.children)) {
+        cat.children.forEach(recurse);
+      }
+    }
+    recurse(category);
+    return ids;
+  };
   useEffect(() => {
-      const collectIds = (categories) => {
-          return categories?.categoryIds?.map(data => data.id) || [];
-        };
-        
-        const ids = collectIds(dataLob[0]);
-        const newQuery = {
-            fq: `category_id_ids:(${ids.join(' OR ')})`,
-            page: 1,
-            brand: router.query.brand || '',
-        };
-        setFinalQuery(newQuery);
-        console.log("finalQuery",finalQuery)
-  }, [dataLob, router.query.brand]);
+    const fetchCategoryData = async () => {
+      if (dataLob[0]?.categoryIds) {
+        for (const category of dataLob[0].categoryIds) {
+          const getCategoriesId = await odooApi('GET', `/api/v1/category/numFound?parent_id=${category.id}`);
+          if (getCategoriesId) {
+            setDataCategoriesProduct(getCategoriesId);
+            const ids = collectIdsCategory(getCategoriesId);
+            dataIdCategories.push(ids)
+          }
+        }
+        setData(dataIdCategories)
+      }
+    };
+    fetchCategoryData();
+    const mergedArray = data.flat();
+    const newQuery = {
+      fq: `category_id_ids:(${mergedArray.join(' OR ')})`,
+    };
+    setFinalQuery(newQuery);
+  }, [dataLob, ]);
 
   return (
     <BasicLayout>
@@ -64,9 +94,16 @@ export default function CategoryDetail() {
       />
 
       <Breadcrumb categoryId={getIdFromSlug(slug)} />
+      <div className='grid grid-cols-3'>
+        {dataLob[0]?.categoryIds && (
+          <div>
+            <image></image>
+          </div>
+        )}
+      </div>
 
       {!_.isEmpty(router.query) && (
-        <ProductSearch query={finalQuery} categories={getIdFromSlug(slug)} prefixUrl={`/shop/lob/${slug}`} />
+        <ProductSearch query={query} categories={getIdFromSlug(slug)} prefixUrl={`/shop/lob/${slug}`} />
       )}
     </BasicLayout>
   );
-- 
cgit v1.2.3


From 556e7e226a2043d43bc55bf0ff2118294bb9f330 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Mon, 29 Jul 2024 13:32:39 +0700
Subject: <iman> update lob category

---
 src/pages/shop/lob/[slug].jsx | 48 -------------------------------------------
 1 file changed, 48 deletions(-)

(limited to 'src/pages/shop/lob/[slug].jsx')

diff --git a/src/pages/shop/lob/[slug].jsx b/src/pages/shop/lob/[slug].jsx
index d02ec8ac..2153b565 100644
--- a/src/pages/shop/lob/[slug].jsx
+++ b/src/pages/shop/lob/[slug].jsx
@@ -32,54 +32,6 @@ export default function CategoryDetail() {
     query.q = q;
   }
 
-  useEffect(() => {
-    const fetchCategoryData = async () => {
-      try {
-        const lobData = await odooApi('GET', `/api/v1/lob_homepage?lob_id=${lobId}`);
-        setDataLob(lobData);
-      } catch (error) {
-        console.error("Error fetching category data:", error);
-      }
-    };
-
-    fetchCategoryData();
-  }, [lobId]);
-
-  const collectIdsCategory = (category) => {
-    const ids = [];
-    function recurse(cat) {
-      if (cat && cat.id) {
-        ids.push(cat.id);
-      }
-      if (Array.isArray(cat.children)) {
-        cat.children.forEach(recurse);
-      }
-    }
-    recurse(category);
-    return ids;
-  };
-  useEffect(() => {
-    const fetchCategoryData = async () => {
-      if (dataLob[0]?.categoryIds) {
-        for (const category of dataLob[0].categoryIds) {
-          const getCategoriesId = await odooApi('GET', `/api/v1/category/numFound?parent_id=${category.id}`);
-          if (getCategoriesId) {
-            setDataCategoriesProduct(getCategoriesId);
-            const ids = collectIdsCategory(getCategoriesId);
-            dataIdCategories.push(ids)
-          }
-        }
-        setData(dataIdCategories)
-      }
-    };
-    fetchCategoryData();
-    const mergedArray = data.flat();
-    const newQuery = {
-      fq: `category_id_ids:(${mergedArray.join(' OR ')})`,
-    };
-    setFinalQuery(newQuery);
-  }, [dataLob, ]);
-
   return (
     <BasicLayout>
       <Seo
-- 
cgit v1.2.3


From 7c2a69c9b48c1930dc3f7cbef20d6479b3047ca2 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Mon, 29 Jul 2024 17:13:30 +0700
Subject: <iman> update category lob

---
 src/pages/shop/lob/[slug].jsx | 49 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)

(limited to 'src/pages/shop/lob/[slug].jsx')

diff --git a/src/pages/shop/lob/[slug].jsx b/src/pages/shop/lob/[slug].jsx
index 2153b565..cdaf3c91 100644
--- a/src/pages/shop/lob/[slug].jsx
+++ b/src/pages/shop/lob/[slug].jsx
@@ -24,8 +24,55 @@ export default function CategoryDetail() {
   const categoryName = getNameFromSlug(slug);
   const lobId = getIdFromSlug(slug);
   const q = router?.query.q || null;
+
+  useEffect(() => {
+    if(router.pathname.includes('lob')){
+      const loadProduct = async () => {
+        const lobData = await odooApi('GET', `/api/v1/lob_homepage/${lobId}/category_id`);
+         
+        if (lobData) {
+          setDataLob(lobData);
+        }
+      };
+      loadProduct();
+      
+    }
+  }, [lobId]);
+
+  useEffect(() => {
+     if (router.pathname.includes('lob')){
+      
+      const fetchCategoryData = async () => {
+        if (dataLob[0]?.categoryIds) {
+          
+          for (const cate of dataLob[0].categoryIds) {
+           
+            dataIdCategories.push(cate.childId)
+          }
+          
+        
+          setData(dataIdCategories.flat())
+         
+          // const newQuery = {
+          //   fq: `category_id_ids:(${mergedArray.join(' OR ')})`,
+          //   category : router.query.category? router.query.category : '',
+          //   page : router.query.page? router.query.page : 1,
+          //   brand : router.query.brand? router.query.brand : '',
+          //   priceFrom,
+          //   priceTo,
+          //   limit,
+          //   orderBy
+          // };
+       
+          // setFinalQuery(newQuery);
+         
+        }
+      };
+      fetchCategoryData();
+    }
+  }, [dataCategoriesProduct, dataLob]);
   const query = {
-    fq: `id:${lobId}`,
+    fq: `category_id_ids:(${data.join(' OR ')})`,
     page,
   };
   if (q) {
-- 
cgit v1.2.3


From 593c508bb87451a985a5aec7e9d7bde45b18074b Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Tue, 30 Jul 2024 09:53:35 +0700
Subject: <iman> update category lob

---
 src/pages/shop/lob/[slug].jsx | 63 +------------------------------------------
 1 file changed, 1 insertion(+), 62 deletions(-)

(limited to 'src/pages/shop/lob/[slug].jsx')

diff --git a/src/pages/shop/lob/[slug].jsx b/src/pages/shop/lob/[slug].jsx
index cdaf3c91..d939c25c 100644
--- a/src/pages/shop/lob/[slug].jsx
+++ b/src/pages/shop/lob/[slug].jsx
@@ -25,60 +25,6 @@ export default function CategoryDetail() {
   const lobId = getIdFromSlug(slug);
   const q = router?.query.q || null;
 
-  useEffect(() => {
-    if(router.pathname.includes('lob')){
-      const loadProduct = async () => {
-        const lobData = await odooApi('GET', `/api/v1/lob_homepage/${lobId}/category_id`);
-         
-        if (lobData) {
-          setDataLob(lobData);
-        }
-      };
-      loadProduct();
-      
-    }
-  }, [lobId]);
-
-  useEffect(() => {
-     if (router.pathname.includes('lob')){
-      
-      const fetchCategoryData = async () => {
-        if (dataLob[0]?.categoryIds) {
-          
-          for (const cate of dataLob[0].categoryIds) {
-           
-            dataIdCategories.push(cate.childId)
-          }
-          
-        
-          setData(dataIdCategories.flat())
-         
-          // const newQuery = {
-          //   fq: `category_id_ids:(${mergedArray.join(' OR ')})`,
-          //   category : router.query.category? router.query.category : '',
-          //   page : router.query.page? router.query.page : 1,
-          //   brand : router.query.brand? router.query.brand : '',
-          //   priceFrom,
-          //   priceTo,
-          //   limit,
-          //   orderBy
-          // };
-       
-          // setFinalQuery(newQuery);
-         
-        }
-      };
-      fetchCategoryData();
-    }
-  }, [dataCategoriesProduct, dataLob]);
-  const query = {
-    fq: `category_id_ids:(${data.join(' OR ')})`,
-    page,
-  };
-  if (q) {
-    query.q = q;
-  }
-
   return (
     <BasicLayout>
       <Seo
@@ -93,16 +39,9 @@ export default function CategoryDetail() {
       />
 
       <Breadcrumb categoryId={getIdFromSlug(slug)} />
-      <div className='grid grid-cols-3'>
-        {dataLob[0]?.categoryIds && (
-          <div>
-            <image></image>
-          </div>
-        )}
-      </div>
 
       {!_.isEmpty(router.query) && (
-        <ProductSearch query={query} categories={getIdFromSlug(slug)} prefixUrl={`/shop/lob/${slug}`} />
+        <ProductSearch query={router.query} categories={getIdFromSlug(slug)} prefixUrl={`/shop/lob/${slug}`} />
       )}
     </BasicLayout>
   );
-- 
cgit v1.2.3

